
//设定时间格式化函数
Date.prototype.format = function (format) {
    var args = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
    };
    if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var i in args) {
        var n = args[i];
        if (new RegExp("(" + i + ")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length));
    }
    return format;
};
var version='0.0.1';
var dataStr = new Date().format('yyyyMMdd');
var fs=require("fs");
var uglifyjs=require("uglify-js");
var dir=process.cwd()+'/dist/avalon/';
var js='dist/avalon/js/';
var com='dist/avalon/components/';
var common = fs.readFileSync('dist/common.js').toString();
var avalon = fs.readFileSync(js+'avalon.modern.js').toString();
var fetch = fs.readFileSync(js+'fetch.js').toString();
var mmRouter = fs.readFileSync(js+'mmRouter.js').toString();
// var clodop = fs.readFileSync(com+'clodop.js').toString();
var modal = fs.readFileSync(com+'modal.js').toString();
var liveSearch = fs.readFileSync(com+'liveSearch.js').toString();
var after = fs.readFileSync('dist/after.js').toString();
var base = uglifyjs.minify([
    // common,avalon,fetch,mmRouter,modal,liveSearch,after
    'dist/common.js',
    js+'avalon.modern.js',
    js+'fetch.js',
    js+'mmRouter.js',
    com+'modal.js',
    com+'liveSearch.js',
    'dist/after.js'
]
//     ,{
//     outSourceMap: 'base@'+dataStr+'.min.js.map',
//     sourceRoot:'/',
//     sourceMapUrl: 'base@'+dataStr+'.min.js.map',
//     outFileName: "out.js",
//     fromString: false,
//     // sourceMap:{
//     //     filename:'dist/base@'+dataStr+'.min.js',
//     //     url:'dist/base@'+dataStr+'.min.js.map',
//     //     root:'/'
//     // }
// }
);
// console.log(result)
fs.writeFile('dist/base@'+dataStr+'.min.js',base.code)
fs.writeFile('dist/base@'+dataStr+'.min.js.map',base.map)

var castle = uglifyjs.minify([
    // 'dist/castle.js',
    fs.readFileSync('dist/castle.js').toString()
],{
    sourceMap:{
        filename:'dist/castle@'+dataStr+'.min.js',
        url:'dist/castle@'+dataStr+'.min.js.map',
        root:'/'
    }
});
// console.log(result)
fs.writeFile('dist/castle@'+dataStr+'.min.js',castle.code);
fs.writeFile('dist/castle@'+dataStr+'.min.js.map',castle.map);


